const {
  getDbInstance,
  initDatabase,
  closeDatabase,
  upgradeDatabase,
} = require("./database.js");
const {
  getUserDownloadsByDeviceId,
  getDownloadStatusCount,
  deleteDownloadByTaskIds,
  insertDownloadItem,
  insertDownloadItems,
  updateDownloadStatus,
  updateDownloadDir,
  updateDownloadStatusBulk,
  getDownloadByTaskid,
} = require("./download.js");
const {
  insertUploadItem,
  insertUploadItems,
  getUserUploadsByDeviceId,
  getUploadStatusCount,
  updateUploadStatus,
  deleteUploadByTaskIds,
  updateUploadStatusBulk,
  getUploadByTaskid,
} = require("./upload.js");

function initialize(dbInstance) {
  return new Promise((resolve, reject) => {
    initDatabase(dbInstance, (error) => {
      error ? reject(error) : resolve();
    });
  });
}

module.exports = {
  getDbInstance,
  initialize,
  closeDatabase,
  upgradeDatabase,
  download: {
    getUserDownloadsByDeviceId,
    getDownloadStatusCount,
    deleteDownloadByTaskIds,
    insertDownloadItem,
    insertDownloadItems,
    updateDownloadStatus,
    updateDownloadDir,
    updateDownloadStatusBulk,
    getDownloadByTaskid,
  },
  upload: {
    insertUploadItem,
    insertUploadItems,
    getUserUploadsByDeviceId,
    getUploadStatusCount,
    updateUploadStatus,
    deleteUploadByTaskIds,
    updateUploadStatusBulk,
    getUploadByTaskid,
  },
};
